import http from "./http";
import md5 from "js-md5";
//注册用户
export function register(name, psw) {
    return http.post('user/register', {
        loginName: name,
        password: psw
    })
}
//用户登录
export function login(name, psw) {
    return http.post('user/login', {
        loginName: name,
        passwordMd5: md5(psw)
    })
}
export function getIndexInfo() {
    return http.get("/index-infos")
}
//获取商品详情
export function getInfoData(id) {
    return http.get('/goods/detail/' + id)
}
//添加到购物车
export function addCart(options) {
    return http.post('/shop-cart', options)
}
//获取购物车商品
export function getCartList() {
    return http.get('/shop-cart')
}
//删除购物车商品
export function deleteCartList(val) {
    return http.delete(`/shop-cart/${val}`)
}

//改变购物车商品数量
export function changeGoodsNumber(params) {
   return http.put("/shop-cart",params)
}
//添加地址
export function addAddress(params) {
    return http.post('/address', params);
  }

 //获取地址
  export function getAddressList() {
    return http.get('/address', { pageNumber: 1, pageSize: 1000 })
  }

  //编辑地址
  export function updateAddress(obj) {
    console.log("接口",obj);
    return http.put('/address', obj)
}

  //编辑地址数据回显
  export function getAddressDetail(id) {
    return http.get('/address/' + id)
}
  //删除地址
export function DeleteAddress(id) {
    console.log(id);
    return http.delete(`/address/${id}`);
  }

  //订单页获取选中的商品
  export function defaultGoods(params) {

    return http.get(`shop-cart/settle?cartItemIds=${params}`)
  }

  //保存订单
  export function saveOrder(params) {
    return http.post('/saveOrder', params)
  }
  //支付成功
  export function paySuccess(params) {
    return http.get(`/paySuccess`,{params})
  }
  //获取订单
  export function getAllOrder(params) {
    return http.get(`/order`,{params})
  }
  //获取单个订单
  export function getItemOrder(params) {                                                
    return http.get(`/order/${params}`)
  }
  //改变单个订单
  export function changeOrderStatue(params) {
    return http.put(`/order/${params}/finish`)
  }
  //User页获取账号信息
  export function userIDCard() {
    return http.get(`/user/info`)
  }
  //修改账号信息
  export function userUpdate(introduceSign,nickName,password) {
    return http.put(`user/info`,{
      introduceSign,
      nickName,
      passwordMd5:md5(password)
    })
  }
    //获取分类页信息
  export function categories() {
    return http.get(`/categories`)
  }
  //获取分类商品信息
  export function getCateList(params) {
    return http.get(`/search`,{params})
  }

